package tests;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import sourceFiles.*;

/*import sourceFiles.ChildEntry;
 import sourceFiles.Ride;
 import sourceFiles.RideState;*/

import Exceptions.*;
import Exceptions.CentralComputerExceptions.*;
/**
 * This test class is a unit test for the class CentralComputer
 * 
 * @author LASO-Team
 *
 */

public class CentralComputerTest {
	static private String masterXMLFilePath;
	static private String copyXMLFilePath;
	static private int numOfInitialRides;

	static private final int RANDOM_TEST_SIZE = 7;
	static private final int[] EDGE_OF_LEGAL_INT_VALUES = { 1, 2 };
	static private final int[] EDGE_OF_ILLEGAL_INT_VALUES = { -1, 0 };
	static private final int TEST_SIZE = RANDOM_TEST_SIZE
			+ EDGE_OF_LEGAL_INT_VALUES.length;
	private static final String IN_PROJECT_PATH_TO_TESTS = "\\src\\tests";
	static private final int MAX_RANDOM = 100;
	static private String[] legalRideNames;
	static private int[] legalMaxCapacities;
	static private int[] legalMinAges;
	static private int[] legalMinHeights;
	static private boolean[] isExtremeRides;
	static private int[] illegalMaxCapacities;
	static private int[] illegalMinAges;
	static private int[] illegalMinHeights;
	static private int[] illegalRideIDs;

	static private int[] legalChildIDs;

	static private int[] legalGuardianIDs;

	static private int[] illegalChildIDs;
	static private int[] illegalGuardianIDs;
	static private int[] nonExistingLegalChildIDs;
	static private int[] nonExistingLegalGuardianIDs;

	static private int[] billingInfo;

	/**
	 * Initiating all the static arrays above with test values, as well as
	 * random parameters (number of tests, TEST_SIZE, is determined by the
	 * number of test values as well as the number of random values
	 * 
	 * @throws Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		assertTrue(EDGE_OF_LEGAL_INT_VALUES.length == EDGE_OF_ILLEGAL_INT_VALUES.length);
		String currentPath = new java.io.File(".").getCanonicalPath();
		currentPath = currentPath + IN_PROJECT_PATH_TO_TESTS;
		masterXMLFilePath = currentPath + "\\TestsMaster.xml";
		copyXMLFilePath = currentPath + "\\results\\ResultsUnitCentralComputer.xml";

		LinkedList<Integer> legalMaxCapacitiesList = new LinkedList<Integer>();
		LinkedList<Integer> legalMinAgesList = new LinkedList<Integer>();
		LinkedList<Integer> legalMinHeightsList = new LinkedList<Integer>();

		LinkedList<Integer> illegalMaxCapacitiesList = new LinkedList<Integer>();
		LinkedList<Integer> illegalMinAgesList = new LinkedList<Integer>();
		LinkedList<Integer> illegalMinHeightsList = new LinkedList<Integer>();
		LinkedList<Integer> illegalRideIDsList = new LinkedList<Integer>();

		LinkedList<Integer> legalChildIDsList = new LinkedList<Integer>();
		LinkedList<Integer> illegalChildIDsList = new LinkedList<Integer>();

		LinkedList<Integer> legalGuardianIDsList = new LinkedList<Integer>();
		LinkedList<Integer> illegalGuardianIDsList = new LinkedList<Integer>();
		LinkedList<Integer> nonExistingLegalChildIDsList = new LinkedList<Integer>();
		LinkedList<Integer> nonExistingLegalGuardianIDsList = new LinkedList<Integer>();

		int numOfEdgeTests = EDGE_OF_LEGAL_INT_VALUES.length;
		for (int i = 0; i < numOfEdgeTests; i++) { // init the legal value first
			legalMaxCapacitiesList.add(EDGE_OF_LEGAL_INT_VALUES[i]);
			legalMinAgesList.add(EDGE_OF_LEGAL_INT_VALUES[i]);
			legalMinHeightsList.add(EDGE_OF_LEGAL_INT_VALUES[i]);
			illegalMaxCapacitiesList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);
			illegalMinAgesList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);
			illegalMinHeightsList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);
			illegalRideIDsList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);

			legalChildIDsList.add(EDGE_OF_LEGAL_INT_VALUES[i]);
			illegalChildIDsList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);

			legalGuardianIDsList.add(EDGE_OF_LEGAL_INT_VALUES[i]);
			illegalGuardianIDsList.add(EDGE_OF_ILLEGAL_INT_VALUES[i]);

		}

		Random rand = new Random();
		int newRandID;
		for (int i = 0; i < RANDOM_TEST_SIZE; i++) {
			// makes sure that the ID created is a unique ID
			newRandID = rand.nextInt(MAX_RANDOM) + 1;
			while (legalChildIDsList.contains(newRandID)) {
				newRandID = rand.nextInt(MAX_RANDOM) + 1;
			}
			legalChildIDsList.add(newRandID);
			legalGuardianIDsList.add(newRandID);

			legalMaxCapacitiesList.add(rand.nextInt(MAX_RANDOM) + 1);
			legalMinAgesList.add(rand.nextInt(MAX_RANDOM) + 1);
			legalMinHeightsList.add(rand.nextInt(MAX_RANDOM) + 1);

			illegalMaxCapacitiesList.add(-rand.nextInt(MAX_RANDOM));
			illegalMinAgesList.add(-rand.nextInt(Integer.MAX_VALUE));
			illegalMinHeightsList.add(-rand.nextInt(Integer.MAX_VALUE));
			illegalRideIDsList.add(-rand.nextInt(Integer.MAX_VALUE));

			illegalChildIDsList.add(-rand.nextInt(Integer.MAX_VALUE));

			illegalGuardianIDsList.add(-rand.nextInt(Integer.MAX_VALUE));

		}

		// add legal child and guardian IDs that will not be created
		for (int i = 0; i < TEST_SIZE; i++) {
			newRandID = rand.nextInt(MAX_RANDOM) + 1;
			while ((legalChildIDsList.contains(newRandID))
					|| (legalGuardianIDsList.contains(newRandID))) {
				newRandID = rand.nextInt(MAX_RANDOM) + 1;
			}
			nonExistingLegalChildIDsList.add(newRandID);
			nonExistingLegalGuardianIDsList.add(newRandID);

		}

		assertTrue(legalChildIDsList.size() == TEST_SIZE
				&& legalGuardianIDsList.size() == TEST_SIZE);

		legalRideNames = new String[TEST_SIZE];
		legalMaxCapacities = new int[TEST_SIZE];
		legalMinAges = new int[TEST_SIZE];
		legalMinHeights = new int[TEST_SIZE];
		isExtremeRides = new boolean[TEST_SIZE];
		illegalMaxCapacities = new int[TEST_SIZE];
		illegalMinAges = new int[TEST_SIZE];
		illegalMinHeights = new int[TEST_SIZE];
		illegalRideIDs = new int[TEST_SIZE];

		legalChildIDs = new int[TEST_SIZE];
		legalGuardianIDs = new int[TEST_SIZE];
		illegalChildIDs = new int[TEST_SIZE];
		illegalGuardianIDs = new int[TEST_SIZE];
		nonExistingLegalChildIDs = new int[TEST_SIZE];
		nonExistingLegalGuardianIDs = new int[TEST_SIZE];
		billingInfo = new int[TEST_SIZE];

		for (int i = 0; i < TEST_SIZE; i++) {
			legalRideNames[i] = UUID.randomUUID().toString();
			legalMaxCapacities[i] = legalMaxCapacitiesList.get(i);
			legalMinAges[i] = legalMinAgesList.get(i);
			legalMinHeights[i] = legalMinHeightsList.get(i);
			isExtremeRides[i] = rand.nextBoolean();

			illegalMaxCapacities[i] = illegalMaxCapacitiesList.get(i);
			illegalMinAges[i] = illegalMinAgesList.get(i);
			illegalMinHeights[i] = illegalMinHeightsList.get(i);
			illegalRideIDs[i] = illegalRideIDsList.get(i);

			legalChildIDs[i] = legalChildIDsList.get(i);
			legalGuardianIDs[i] = legalGuardianIDsList.get(i);
			illegalChildIDs[i] = illegalChildIDsList.get(i);
			illegalGuardianIDs[i] = illegalGuardianIDsList.get(i);

			nonExistingLegalChildIDs[i] = nonExistingLegalChildIDsList.get(i);
			nonExistingLegalGuardianIDs[i] = nonExistingLegalGuardianIDsList.get(i);
			billingInfo[i] = rand.nextInt();
		}
		return;
	}

	/**
	 * Preparing a new XML file for the use of the current test 
	 * 
	 * @throws IOException
	 */
	@Before
	public void setUp() throws IOException {
		copySourceFile();
	}

	/**
	 * Creates a new copy of the XML file by coping the data from the master XML file to e the new XML file.
	 * 
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	private void copySourceFile() throws FileNotFoundException, IOException {
		InputStream inStream = null;
		OutputStream outStream = null;

		File afile = new File(masterXMLFilePath);
		File bfile = new File(copyXMLFilePath);

		inStream = new FileInputStream(afile);
		outStream = new FileOutputStream(bfile);

		byte[] buffer = new byte[1024];

		int length;
		// copy the file content in bytes
		while ((length = inStream.read(buffer)) > 0) {

			outStream.write(buffer, 0, length);
		}
		inStream.close();
		outStream.close();
	}

	/**
	 * This method tests the constructor of the central computer which uses an XML file. 
	 * This method checks that we cannot create a computer with null instead of an XML file.
	 * This method checks that we cannot create a computer with a non-existing file.
	 * This method checks that we can create a computer with a valid XML file.
	 * 
	 * @throws XMLRidesParserException
	 */
	@Test
	public void testCentralComputerCtor() throws XMLRidesParserException {
		@SuppressWarnings("unused")
		CentralComputer cc;
		try {
			cc = new CentralComputer(null);
			fail("tried to create a CentralComputer with an invalid file");
		} catch (XMLRidesParserException e) {
		}
		try {
			cc = new CentralComputer("aaa");
			fail("tried to create a CentralComputer with an invalid file");
		} catch (XMLRidesParserException e) {
		}
		cc = new CentralComputer(copyXMLFilePath);
	}

	/**
	 * This method tests the process of creating a new ride.
	 * This method checks that we cannot create a new ride with an illegal ride name.
	 * This method checks that we cannot create a new ride with an illegal max capacity.
	 * This method checks that we cannot create a new ride with an illegal minimum age.
	 * This method checks that we cannot create a new ride with an illegal minimum height.
	 * This method checks that we can create a new ride with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws InvalidCapacity
	 * @throws InvalidAgeParam
	 * @throws InvalidHeightParam
	 * @throws InvalidRideName
	 */
	@Test
	public void testCreateRide() throws XMLRidesParserException,
			InvalidCapacity, InvalidAgeParam, InvalidHeightParam,
			InvalidRideName {
		CentralComputer cc = new CentralComputer(copyXMLFilePath);
		numOfInitialRides = cc.getRidesList().size();
		testIllegalRideNameInCreateRide(cc);
		testIllegalMaxCapacityInCreateRide(cc);
		testIllegalMinAgeInCreateRide(cc);
		testIllegalMinHeightInCreateRide(cc);
		testLegalParamsInCreateRide(cc);
	}

	/**
	 * This method tests the process of creating a new ride with legal parameters.
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidAgeParam
	 * @throws InvalidHeightParam
	 * @throws XMLRidesParserException
	 */
	private void testLegalParamsInCreateRide(CentralComputer cc)
			throws InvalidRideName, InvalidCapacity, InvalidAgeParam,
			InvalidHeightParam, XMLRidesParserException {
		LinkedList<IRide> ridesList = cc.getRidesList();
		LinkedList<RideEntry> ridesCatalog = cc.getRidesCatalog();
		assertTrue(ridesList.size() == numOfInitialRides
				&& ridesCatalog.size() == numOfInitialRides);
		for (int i = 0; i < TEST_SIZE; i++) {
			cc.createRide(legalRideNames[i], isExtremeRides[i],
					legalMaxCapacities[i], legalMinAges[i], legalMinHeights[i]);
		}
		ridesList = cc.getRidesList();
		ridesCatalog = cc.getRidesCatalog();
		int numOfIterations = TEST_SIZE + numOfInitialRides;
		assertTrue(ridesList.size() == numOfIterations
				&& ridesCatalog.size() == numOfIterations);
		for (int i = 0; i < TEST_SIZE; i++) {
			assertTrue(ridesList.get(i + numOfInitialRides).getRideName()
					.equals(legalRideNames[i]));
			assertTrue(ridesList.get(i + numOfInitialRides).getMinimumAge()
					.equals(legalMinAges[i]));
			assertTrue(ridesList.get(i + numOfInitialRides).getMinimumHeight()
					.equals(legalMinHeights[i]));
			assertTrue(ridesList.get(i + numOfInitialRides).getMaxCapacity()
					.equals(legalMaxCapacities[i]));
		}
	}

	/**
	 * This method tests the process of creating a new ride with an illegal minimum height.
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidAgeParam
	 * @throws XMLRidesParserException
	 */
	private void testIllegalMinHeightInCreateRide(CentralComputer cc)
			throws InvalidRideName, InvalidCapacity, InvalidAgeParam,
			XMLRidesParserException {
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.createRide(legalRideNames[i], isExtremeRides[i],
						legalMaxCapacities[i], legalMinAges[i],
						illegalMinHeights[i]);
				fail("Tried to create ride with an illegal minHeight value of "
						+ illegalMinHeights[i]);
			} catch (InvalidHeightParam e) {
			}
		}
	}

	/**
	 * This method tests the process of creating a new ride with an illegal minimum age.
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidHeightParam
	 * @throws XMLRidesParserException
	 */
	private void testIllegalMinAgeInCreateRide(CentralComputer cc)
			throws InvalidRideName, InvalidCapacity, InvalidHeightParam,
			XMLRidesParserException {
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.createRide(legalRideNames[i], isExtremeRides[i],
						legalMaxCapacities[i], illegalMinAges[i],
						legalMinHeights[i]);
				fail("Tried to create ride with an illegal minAge value of "
						+ illegalMinAges[i]);
			} catch (InvalidAgeParam e) {
			}
		}
	}

	
	/**
	 * This method tests the process of creating a new ride with an illegal max capacity.
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @throws InvalidRideName
	 * @throws InvalidAgeParam
	 * @throws InvalidHeightParam
	 * @throws XMLRidesParserException
	 */
	private void testIllegalMaxCapacityInCreateRide(CentralComputer cc)
			throws InvalidRideName, InvalidAgeParam, InvalidHeightParam,
			XMLRidesParserException {
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.createRide(legalRideNames[i], isExtremeRides[i],
						illegalMaxCapacities[i], legalMinAges[i],
						legalMinHeights[i]);
				fail("Tried to create ride with an illegal maxCapacity value of "
						+ illegalMaxCapacities[i]);
			} catch (InvalidCapacity e) {
			}
		}
	}

	/**
	 * This method tests the process of creating a new ride with an illegal ride name.
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @throws InvalidCapacity
	 * @throws InvalidAgeParam
	 * @throws InvalidHeightParam
	 * @throws XMLRidesParserException
	 */
	private void testIllegalRideNameInCreateRide(CentralComputer cc)
			throws InvalidCapacity, InvalidAgeParam, InvalidHeightParam,
			XMLRidesParserException {
		try {
			cc.createRide(null, isExtremeRides[0], illegalMaxCapacities[0],
					legalMinAges[0], legalMinHeights[0]);
			fail("Tried to create ride with a null name parameter");
		} catch (InvalidRideName e) {
		}
	}

	/**
	 * This method tests the process of updating a ride.
	 * This method checks that we cannot update a ride with an illegal max capacity.
	 * This method checks that we cannot update a ride with an illegal minimum age.
	 * This method checks that we cannot update a ride with an illegal minimum height.
	 * This method checks that we cannot update a ride with an illegal ride ID number.
	 * This method checks that we cannot update a ride with a rideID of a ride which does not exist in the central computer.
	 * This method checks that we can update a ride with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidAgeParam
	 * @throws InvalidHeightParam
	 * @throws InvalidRideId
	 * @throws RideIDDoesntExist
	 */
	@Test
	public void testUpdateRide() throws XMLRidesParserException,
			InvalidRideName, InvalidCapacity, InvalidAgeParam,
			InvalidHeightParam, InvalidRideId, RideIDDoesntExist {
		
		//Initializing all the relevant variables for the test.
		CentralComputer cc = new CentralComputer(copyXMLFilePath);
		LinkedList<IRide> ridesList = cc.getRidesList();
		LinkedList<RideEntry> ridesCatalog = cc.getRidesCatalog();
		assertTrue(ridesList.size() == numOfInitialRides
				&& ridesCatalog.size() == numOfInitialRides);
		for (int i = 0; i < TEST_SIZE; i++) {
			cc.createRide(legalRideNames[i], isExtremeRides[i],
					legalMaxCapacities[i], legalMinAges[i], legalMinHeights[i]);
		}
		Integer[] existingRideIDs = new Integer[ridesList.size()];
		for (int i = 0; i < existingRideIDs.length; i++) {
			existingRideIDs[i] = ridesList.get(i).getRideID();
		}
		// now we have all the rides.

		// updating ride with illegal capacity
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.updateRide(existingRideIDs[i], illegalMaxCapacities[i],
						legalMinAges[i], legalMinHeights[i]);
				fail("Tried to update ride with an illegal maxCapacity value of "
						+ illegalMaxCapacities[i]);
			} catch (InvalidCapacity e) {
			}
		}

		// updating ride with illegal age
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.updateRide(existingRideIDs[i], legalMaxCapacities[i],
						illegalMinAges[i], legalMinHeights[i]);
				fail("Tried to update ride with an illegal minAge value of "
						+ illegalMinAges[i]);
			} catch (InvalidAgeParam e) {
			}
		}

		// updating ride with illegal height
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.updateRide(existingRideIDs[i], legalMaxCapacities[i],
						legalMinAges[i], illegalMinHeights[i]);
				fail("Tried to update ride with an illegal minHeight value of "
						+ illegalMinHeights[i]);
			} catch (InvalidHeightParam e) {
			}
		}

		// updating ride with illegal rideID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.updateRide(illegalRideIDs[i], legalMaxCapacities[i],
						legalMinAges[i], legalMinHeights[i]);
				fail("Tried to update ride with an illegal RideID value of "
						+ illegalRideIDs[i]);
			} catch (InvalidRideId e) {
			}
		}

		// finding a non-existing RideID and trying to update the ride with it
		int newRandID = findNonExistindRandomRideID(cc);
		try {
			cc.updateRide(newRandID, legalMaxCapacities[0], legalMinAges[0],
					legalMinHeights[0]);
			fail("Tried to update ride with a non-existing RideID value of "
					+ newRandID);
		} catch (RideIDDoesntExist e) {
		}

		// checking if the ride was properly updated
		for (int i = 0; i < ridesList.size(); i++) {
			cc.updateRide(existingRideIDs[i], legalMaxCapacities[0],
					legalMinAges[0], legalMinHeights[0]);
		}

		for (int i = 0; i < ridesList.size(); i++) {
			assertTrue(ridesList.get(i).getMinimumAge().equals(legalMinAges[0]));
			assertTrue(ridesList.get(i).getMinimumHeight()
					.equals(legalMinHeights[0]));
			assertTrue(ridesList.get(i).getMaxCapacity()
					.equals(legalMaxCapacities[0]));
		}
	}
	

	/**
	 * This method tests the process of adding a guardian.
	 * This method checks that we cannot add a guardian with an illegal guardian ID number.
	 * This method checks that we cannot add a guardian with an ID number which already exists in the central computer.
	 * This method checks that we can add a guardian with legal parameters.
	 * 
	 * @throws GuardianAlreadyExist
	 * @throws XMLRidesParserException
	 * @throws InvalidGuardianID
	 */
	@Test
	public void testAddGuardian() throws GuardianAlreadyExist,
			XMLRidesParserException, InvalidGuardianID {
		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// trying to create guardians with illegal guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addGuardian(illegalGuardianIDs[i], billingInfo[i]);
				fail("Tried to add guardian with an illegal ID value of "
						+ illegalGuardianIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}
		assertTrue(cc.getGuardiansList().size() == 0);

		// creating legal guardian.
		String password = cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);

		assertTrue(cc.getGuardiansList().size() == 1);

		assertTrue(cc.getGuardiansList().get(0).getPassword().equals(password));
		assertTrue(cc.getGuardiansList().get(0).getID()
				.equals(legalGuardianIDs[0]));

		// trying to create guardian with an ID number which already exists in the central computer.
		try {
			cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);
			fail("Tried to add guardian with existing legal ID value of "
					+ legalGuardianIDs[0]);
		} catch (GuardianAlreadyExist e) {
		}
	}

	/**
	 * This method tests the process of adding a child to an existing guardian.
	 * This method checks that we cannot add a child with an illegal guardian ID number.
	 * This method checks that we cannot add a child with a guardian ID number which does not exist in the central computer. .
	 * This method checks that we cannot add a child with an illegal child ID number.
	 * This method checks that we cannot add a child with an illegal age value.
	 * This method checks that we cannot add a child with an illegal height value. 
	 * This method checks that we cannot add a child with an ID number which already exists in the central computer.
	 * This method checks that we can add a child with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws GuardianAlreadyExist
	 * @throws InvalidGuardianID
	 * @throws InvalidChildID
	 */
	@Test
	public void testAddChildToGuardian() throws XMLRidesParserException,
			GuardianIDDoesntExist, InvalidHeightParam, InvalidAgeParam,
			ChildAlreadyExist, GuardianAlreadyExist, InvalidGuardianID,
			InvalidChildID {
		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating a legal guardian.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);

		// trying to create child with illegal guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(illegalGuardianIDs[i], legalChildIDs[i],
						legalMinAges[i], legalMinHeights[i]);
				fail("Tried to add child to guardian with an illegal guardianID value of "
						+ illegalGuardianIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}

		// trying to create child with non-existing guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(nonExistingLegalGuardianIDs[i],
						legalChildIDs[i], legalMinAges[i], legalMinHeights[i]);
				fail("Tried to add child to guardian with a non-existing guardian ID  value of "
						+ nonExistingLegalGuardianIDs[i]);
			} catch (GuardianIDDoesntExist e) {
			}
		}

		// trying to create child with illegal ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(legalGuardianIDs[0], illegalChildIDs[i],
						legalMinAges[i], legalMinHeights[i]);
				fail("Tried to add child to guardian with an illegal childID value of "
						+ illegalChildIDs[i]);
			} catch (InvalidChildID e) {
			}
		}

		// trying to create child with illegal age value.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[i],
						illegalMinAges[i], legalMinHeights[i]);
				fail("Tried to add child to guardian with an illegal age value of "
						+ illegalMinAges[i]);
			} catch (InvalidAgeParam e) {
			}
		}

		// trying to create child with illegal height value.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[i],
						legalMinAges[i], illegalMinHeights[i]);
				fail("Tried to add child to guardian with an illegal height value of "
						+ illegalMinHeights[i]);
			} catch (InvalidHeightParam e) {
			}
		}

		// adding a child with legal parameters.
		assertTrue(cc.getGuardiansList().get(0).getChildrenList().size() == 0);
		assertTrue(cc.getChildrenList().size() == 0);
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
				legalMinAges[0], legalMinHeights[0]);
		assertTrue(cc.getGuardiansList().get(0).getChildrenList().size() == 1);
		assertTrue(cc.getChildrenList().size() == 1);

		// trying to create child which already exists
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
						legalMinAges[0], legalMinHeights[0]);
				fail("Tried to add child which already exist ");
			} catch (ChildAlreadyExist e) {
			}
		}
	}

	/**
	 * This method tests the process of connecting a guardian to the application and the central computer.
	 * This method checks that we cannot connect a guardian with an illegal guardian ID number.
	 * This method checks that we cannot connect a guardian using null instead of a password.
	 * This method checks that we cannot connect a guardian with a guardian ID number which does not exist in the central computer.
	 * This method checks that we cannot connect a guardian with a non-matching password.
	 * This method checks that we can connect a guardian with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws GuardianAlreadyExist
	 * @throws InvalidPassword
	 * @throws GuardianIDDoesntExist
	 * @throws ErrorInGuardianPassword
	 * @throws InvalidGuardianID
	 */
	@Test
	public void testConnectGuardian() throws XMLRidesParserException,
			GuardianAlreadyExist, InvalidPassword, GuardianIDDoesntExist,
			ErrorInGuardianPassword, InvalidGuardianID {
		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating a legal guardian.
		String password = cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);

		// trying to connect a guardian with illegal guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.connectGuardian(illegalGuardianIDs[i], password);
				fail("Tried to connect the guardian with an illegal guardianID value of "
						+ illegalGuardianIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}

		// trying to connect a guardian with a null password.
		try {
			cc.connectGuardian(legalGuardianIDs[0], null);
			fail("Tried to connect the guardian with a null password ");
		} catch (InvalidPassword e) {
		}

		// trying to connect a non-existing guardian.
		try {
			cc.connectGuardian(nonExistingLegalGuardianIDs[0], password);
			fail("Tried to connect a non-existing guardian with guardianID value of "
					+ nonExistingLegalGuardianIDs[0]);
		} catch (GuardianIDDoesntExist e) {
		}

		// trying to connect a guardian with non-matching password.
		try {
			cc.connectGuardian(legalGuardianIDs[0], password + "aa");
			fail("Tried to connect a non-existing guardian with guardianID value of "
					+ nonExistingLegalGuardianIDs[0]);
		} catch (ErrorInGuardianPassword e) {
		}

		cc.connectGuardian(legalGuardianIDs[0], password);

	}

	/**
	 * This method tests the process of buying a ticket.
	 * This method checks that we cannot buy a ticket with an illegal rideID number.
	 * This method checks that we cannot buy a ticket with an illegal guardian ID number.
	 * This method checks that we cannot buy a ticket with a guardian ID number which does not exist in the central computer.
	 * This method checks that we cannot buy a ticket with a child ID number which does not exist in the central computer.
	 * This method checks that we can buy a ticket with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws GuardianAlreadyExist
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws ChildIDDoesntExist
	 * @throws RideIDDoesntExist
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidRideId
	 * @throws InvalidChildID
	 * @throws InvalidGuardianID
	 */
	@Test
	public void testBuyingProcess() throws XMLRidesParserException,
			GuardianAlreadyExist, GuardianIDDoesntExist, InvalidHeightParam,
			InvalidAgeParam, ChildAlreadyExist, ChildIDDoesntExist,
			RideIDDoesntExist, InvalidRideName, InvalidCapacity, InvalidRideId,
			InvalidChildID, InvalidGuardianID {
		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating a guardian and a child for the test.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
				legalMinAges[0], legalMinHeights[0]);
		// creating a ride for the test
		Integer createdRideID = cc.createRide(legalRideNames[0],
				isExtremeRides[0], legalMaxCapacities[0], legalMinAges[0],
				legalMinHeights[0]);

		// performing a buy with illegal rideID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.buyingProcess(illegalRideIDs[i], legalGuardianIDs[0],
						legalChildIDs[0]);
				fail("Tried to performing a buy with an illegal RideID value of "
						+ illegalRideIDs[i]);
			} catch (InvalidRideId e) {
			}
		}

		int newRandID = findNonExistindRandomRideID(cc);

		try {
			cc.buyingProcess(newRandID, legalGuardianIDs[0], legalChildIDs[0]);
			fail("Tried to performing a buy with an non-existing Ride value of "
					+ newRandID);
		} catch (RideIDDoesntExist e) {
		}

		// performing a buy with illegal guardianID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.buyingProcess(createdRideID, illegalGuardianIDs[i],
						legalChildIDs[0]);
				fail("Tried to performing a buy with an illegal guardianID value of "
						+ illegalRideIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}

		// performing a buy with non-existing guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.buyingProcess(createdRideID, nonExistingLegalGuardianIDs[i],
						legalChildIDs[0]);
				fail("Tried to performing a buy with a non-existing guardian ID  value of "
						+ nonExistingLegalGuardianIDs[i]);
			} catch (GuardianIDDoesntExist e) {
			}
		}

		// performing a buy with non-existing child ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.buyingProcess(createdRideID, legalGuardianIDs[0],
						nonExistingLegalChildIDs[i]);
				fail("Tried to performing a buy with a non-existing child ID  value of "
						+ nonExistingLegalChildIDs[i]);
			} catch (ChildIDDoesntExist e) {
			}
		}

		assertTrue(!cc.getTicketsSold().containsKey(createdRideID));
		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);
		assertTrue(cc.getTicketsSold().get(createdRideID) == 1);

		ChildEntry child = cc.getChildrenList().get(0);
		assertTrue(child.getChildsTicket().getExtremeRidesList().size()
				+ child.getChildsTicket().getRegualrRidesTickets() == 1);

	}


	
	/**
	 * This method tests the process of canceling an acquisition of a ticket.
	 * This method checks that we cannot cancel an acquisition with an illegal rideID number.
	 * This method checks that we cannot cancel an acquisition with a rideID which does not exist in the central computer.
	 * This method checks that we cannot cancel an acquisition with an illegal guardian ID number.
	 * This method checks that we cannot cancel an acquisition with a guardian ID number which does not exist in the central computer.
	 * This method checks that we cannot cancel an acquisition with an illegal child ID number.
	 * This method checks that we cannot cancel an acquisition with a child ID number which does not exist in the central computer.
	 * This method checks that we can cancel an acquisition with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws GuardianAlreadyExist
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws ChildIDDoesntExist
	 * @throws RideIDDoesntExist
	 * @throws TicketDoesntExist
	 * @throws InvalidRideId
	 * @throws InvalidChildID
	 * @throws InvalidGuardianID
	 */
	@Test
	public void testCancelAcquisition() throws XMLRidesParserException,
			GuardianIDDoesntExist, InvalidHeightParam, InvalidAgeParam,
			ChildAlreadyExist, GuardianAlreadyExist, InvalidRideName,
			InvalidCapacity, ChildIDDoesntExist, RideIDDoesntExist,
			TicketDoesntExist, InvalidRideId, InvalidChildID, InvalidGuardianID {

		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating a guardian and a child for the test.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
				legalMinAges[0], legalMinHeights[0]);
		// creating a ride for the test
		Integer createdRideID = cc.createRide(legalRideNames[0],
				isExtremeRides[0], legalMaxCapacities[0], legalMinAges[0],
				legalMinHeights[0]);

		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);

		// canceling a buy with illegal rideID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.cancelAcquisition(illegalRideIDs[i], legalGuardianIDs[0],
						legalChildIDs[0]);
				fail("Tried to performing a buy with an illegal RideID value of "
						+ illegalRideIDs[i]);
			} catch (InvalidRideId e) {
			}
		}

		// canceling a buy with non-existing rideID
		int newRandID = findNonExistindRandomRideID(cc);

		try {
			cc.cancelAcquisition(newRandID, legalGuardianIDs[0],
					legalChildIDs[0]);
			fail("Tried to performing a buy with an non-existing Ride value of "
					+ newRandID);
		} catch (RideIDDoesntExist e) {
		}

		// performing a buy with illegal guardianID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.cancelAcquisition(createdRideID, illegalGuardianIDs[i],
						legalChildIDs[0]);
				fail("Tried to performing a buy with an illegal guardianID value of "
						+ illegalGuardianIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}

		// performing a buy with non-existing guardian ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.cancelAcquisition(createdRideID,
						nonExistingLegalGuardianIDs[i], legalChildIDs[0]);
				fail("Tried to performing a buy with a non-existing guardian ID  value of "
						+ nonExistingLegalGuardianIDs[i]);
			} catch (GuardianIDDoesntExist e) {
			}
		}

		// performing a buy with illegal childID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.cancelAcquisition(createdRideID, legalGuardianIDs[0],
						illegalChildIDs[i]);
				fail("Tried to performing a buy with an illegal childID value of "
						+ illegalChildIDs[i]);
			} catch (InvalidChildID e) {
			}
		}

		// performing a buy with non-existing child ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.cancelAcquisition(createdRideID, legalGuardianIDs[0],
						nonExistingLegalChildIDs[i]);
				fail("Tried to performing a buy with a non-existing child ID  value of "
						+ nonExistingLegalChildIDs[i]);
			} catch (ChildIDDoesntExist e) {
			}
		}

		assertTrue(cc.getTicketsSold().get(createdRideID) == 1);
		cc.cancelAcquisition(createdRideID, legalGuardianIDs[0],
				legalChildIDs[0]);
		assertTrue(!cc.getTicketsSold().containsKey(createdRideID));

		ChildEntry child = cc.getChildrenList().get(0);
		assertTrue(child.getChildsTicket().getExtremeRidesList().size()
				+ child.getChildsTicket().getRegualrRidesTickets() == 0);

	}
	
	

	/**
	 * This method tests the process of validating a child for a given ride. i.e the child can enter the ride.
	 * This method checks that we cannot validate a child for the ride with an illegal rideID number.
	 * This method checks that we cannot validate a child for the ride with an illegal child ID number.
	 * This method checks that we cannot validate a child for the ride with a rideID which does not exist in the central computer.
	 * This method checks that we cannot validate a child for the ride with a child ID number which does not exist in the central computer.
	 * This method checks that we cannot validate a child for the ride with age lower then the minimum age of the ride.
	 * This method checks that we cannot validate a child for the ride with height lower then the minimum height of the ride.
	 * This method checks that we can validate a child for the ride with legal parameters.
	 * 
	 * 
	 * @throws XMLRidesParserException
	 * @throws InvalidGuardianID
	 * @throws GuardianAlreadyExist
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws InvalidChildID
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws RideIDDoesntExist
	 * @throws ChildIDDoesntExist
	 * @throws ChildAgeDoesntMatch
	 * @throws ChildHeightDoesntMatch
	 * @throws TicketDoesntExist
	 * @throws InvalidRideId
	 */
	@Test
	public void testValidateChildForRide() throws XMLRidesParserException,
			InvalidGuardianID, GuardianAlreadyExist, GuardianIDDoesntExist,
			InvalidHeightParam, InvalidAgeParam, ChildAlreadyExist,
			InvalidChildID, InvalidRideName, InvalidCapacity,
			RideIDDoesntExist, ChildIDDoesntExist, ChildAgeDoesntMatch,
			ChildHeightDoesntMatch, TicketDoesntExist, InvalidRideId {

		// to make sure we have enough children for the test
		assertTrue(RANDOM_TEST_SIZE > 3);

		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating rides for the test
		for (int i = 2; i < TEST_SIZE; i++) {
			cc.createRide(legalRideNames[i], isExtremeRides[i],
					legalMaxCapacities[i], legalMinAges[i] + 2,
					legalMinHeights[i] + 2);
			// 2 is added, to make sure the rest of the test will be correct
			// (makes sure that if we subtract from legalMinAges or
			// legalMinHeights, we will not reach zero.
		}

		// creating a guardian and a child for the test.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);

		// creating a child with a lower age
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[2],
				legalMinAges[2] + 1, legalMinHeights[2] + 2);
		// creating a child with a lower height
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[3],
				legalMinAges[3] + 2, legalMinHeights[3] + 1);
		// creating a valid child
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[4],
				legalMinAges[4] + 3, legalMinHeights[4] + 3);

		// trying to Validate Child For Ride with illegal rideID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.validateChildForRide(illegalRideIDs[i], legalChildIDs[i]);
				fail("Tried to Validate Child For Ride  with an illegal RideID value of "
						+ illegalRideIDs[i]);
			} catch (InvalidRideId e) {
			}
		}

		// trying to Validate Child For Ride with illegal childID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.validateChildForRide(cc.getRidesList().get(i).getRideID(),
						illegalChildIDs[i]);
				fail("Tried to Validate Child For Ride  with an illegal RideID value of "
						+ illegalChildIDs[i]);
			} catch (InvalidChildID e) {
			}
		}

		// finding a non-existing RideID and trying to validate a child with it
		int newRandID = findNonExistindRandomRideID(cc);
		// trying to Validate Child For Ride with a non-existing rideID
		try {
			cc.validateChildForRide(newRandID, legalChildIDs[0]);
			fail("Tried to Validate Child For Ride  with a non-existing rideID value of "
					+ newRandID);
		} catch (RideIDDoesntExist e) {
		}

		// trying to Validate Child For Ride with non-existing childID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.validateChildForRide(cc.getRidesList().get(i).getRideID(),
						nonExistingLegalChildIDs[i]);
				fail("Tried to Validate Child For Ride  with a non-existing childID value of "
						+ nonExistingLegalChildIDs[i]);
			} catch (ChildIDDoesntExist e) {
			}
		}

		// trying to Validate Child For Ride with age lower then the minimum age
		try {

			cc.validateChildForRide(cc.getRidesList().get(numOfInitialRides)
					.getRideID(), legalChildIDs[2]);
			fail("Tried to Validate Child For Ride  with age lower then the minimum age of value "
					+ (legalMinAges[2] + 1));
		} catch (ChildAgeDoesntMatch e) {
		}

		// trying to Validate Child For Ride with height lower then the minimum
		try {

			cc.validateChildForRide(cc.getRidesList()
					.get(numOfInitialRides + 1).getRideID(), legalChildIDs[3]);
			fail("Tried to Validate Child For Ride  with height lower then the minimum height of value "
					+ (legalMinHeights[3] + 1));
		} catch (ChildHeightDoesntMatch e) {
		}

		// trying to Validate Child For Ride with valid parameters.
		int currentRideId = cc.getRidesList().get(numOfInitialRides + 2)
				.getRideID();

		cc.buyingProcess(currentRideId, legalGuardianIDs[0], legalChildIDs[4]);

		cc.validateChildForRide(currentRideId, legalChildIDs[4]);

		if (cc.getRidesCatalog().get(numOfInitialRides + 2).getClass()
				.equals(ExtremeRideEntry.class)) {
			assertTrue(cc.getChildrenList().get(2).getChildsTicket()
					.getExtremeRidesList().size() == 0);
		} else if (cc.getRidesCatalog().get(numOfInitialRides + 2).getClass()
				.equals(RegularRideEntry.class)) {
			assertTrue(cc.getChildrenList().get(2).getChildsTicket()
					.getRegualrRidesTickets() == 0);
		}

		assertTrue(cc.getChildrenList().get(2).getRideID() == currentRideId);

	}

	/**
	 * This method finds a new random ride ID which doesn't exist in the central computer. 
	 * 
	 * @param cc - an instance of CentralComputer.
	 * @return
	 */
	private int findNonExistindRandomRideID(CentralComputer cc) {
		Random rand = new Random();
		int newRandID = 0;
		boolean doesIDExists = true;
		while (doesIDExists) {
			newRandID = rand.nextInt(MAX_RANDOM) + 1;
			doesIDExists = false;
			LinkedList<IRide> currentRides = cc.getRidesList();
			for (int i = 0; i < currentRides.size(); i++) {
				if (currentRides.get(i).getRideID() == newRandID) {
					doesIDExists = true;
					break;
				}
			}
		}
		return newRandID;
	}

	
	
	/**
	 * This method tests the process of retrieving the location of all the children of the guardian.
	 * This method checks that we cannot retrieve children's location with an illegal guardian ID number.
	 * This method checks that we cannot retrieve children's location with a guardian ID number which does not exist in the central computer.
	 * This method checks that we cannot retrieve children's location with a guardian which does not have any children.
	 * This method checks that we can retrieve children's location with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws InvalidGuardianID
	 * @throws GuardianAlreadyExist
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws InvalidChildID
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidRideId
	 * @throws ChildIDDoesntExist
	 * @throws RideIDDoesntExist
	 * @throws NoChildrenForGuardian
	 * @throws ChildAgeDoesntMatch
	 * @throws ChildHeightDoesntMatch
	 * @throws TicketDoesntExist
	 */
	@Test
	public void testRetrieveChildrenLocation() throws XMLRidesParserException,
			InvalidGuardianID, GuardianAlreadyExist, GuardianIDDoesntExist,
			InvalidHeightParam, InvalidAgeParam, ChildAlreadyExist,
			InvalidChildID, InvalidRideName, InvalidCapacity, InvalidRideId,
			ChildIDDoesntExist, RideIDDoesntExist, NoChildrenForGuardian,
			ChildAgeDoesntMatch, ChildHeightDoesntMatch, TicketDoesntExist {

		CentralComputer cc = new CentralComputer(copyXMLFilePath);

		// creating a guardian and a child for the test.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);

		// creating a ride for the test
		Integer createdRideID = cc.createRide(legalRideNames[0],
				isExtremeRides[0], legalMaxCapacities[0], legalMinAges[0],
				legalMinHeights[0]);

		// Trying to Retrieve Children Location with illegal guardianID
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.retrieveChildrenLocation(illegalGuardianIDs[i]);
				fail("Tried to Retrieve Children Location with an illegal guardianID value of "
						+ illegalGuardianIDs[i]);
			} catch (InvalidGuardianID e) {
			}
		}

		// Trying to Retrieve Children Location for non-existing guardian ID
		// numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.retrieveChildrenLocation(nonExistingLegalGuardianIDs[i]);
				fail("Tried to Retrieve Children Location with a non-existing guardian ID value of "
						+ nonExistingLegalGuardianIDs[i]);
			} catch (GuardianIDDoesntExist e) {
			}
		}

		// Trying to Retrieve Children Location for a guardian without children.
		assertTrue(cc.getGuardiansList().get(0).getChildrenList().size() == 0);
		try {
			cc.retrieveChildrenLocation(legalGuardianIDs[0]);
			fail("Tried to Retrieve Children Location for a guardian without children. guardian ID value of "
					+ legalGuardianIDs[0]);
		} catch (NoChildrenForGuardian e) {
		}

		// adding one child
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
				legalMinAges[0], legalMinHeights[0]);
		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);
		cc.validateChildForRide(createdRideID,  legalChildIDs[0]);
		
		Map<Integer, Integer> childrensLocationMap;
		
		childrensLocationMap = cc.retrieveChildrenLocation(legalGuardianIDs[0]);
		
		assertTrue(childrensLocationMap.get(legalChildIDs[0]).equals(createdRideID));
		
		// creating more rides for the test
		Integer createdRideID2 = cc.createRide(legalRideNames[1],
				isExtremeRides[1], legalMaxCapacities[1], legalMinAges[1],
				legalMinHeights[1]);
		Integer createdRideID3 = cc.createRide(legalRideNames[2],
				isExtremeRides[2], legalMaxCapacities[2], legalMinAges[2]+2,
				legalMinHeights[2]+2);

		// adding a child for the second createdRideID2
	 	cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[1],
				legalMinAges[1], legalMinHeights[1]);
		cc.buyingProcess(createdRideID2, legalGuardianIDs[0], legalChildIDs[1]);
		cc.validateChildForRide(createdRideID2,  legalChildIDs[1]);
		childrensLocationMap = cc.retrieveChildrenLocation(legalGuardianIDs[0]);
		
		assertTrue(childrensLocationMap.size() == 2);
		assertTrue(childrensLocationMap.get(legalChildIDs[0]).equals(createdRideID));
		assertTrue(childrensLocationMap.get(legalChildIDs[1]).equals(createdRideID2));
	 	
		//this child should not be validated
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[2],
				legalMinAges[2]+1, legalMinHeights[2]+1);
		cc.buyingProcess(createdRideID3, legalGuardianIDs[0], legalChildIDs[2]);
		try {
		cc.validateChildForRide(createdRideID3,  legalChildIDs[2]);
		} catch (ChildAgeDoesntMatch | ChildHeightDoesntMatch e){
			childrensLocationMap = cc.retrieveChildrenLocation(legalGuardianIDs[0]);
			int iSize = childrensLocationMap.size();
			assertTrue(iSize == 2);	
		}
		
		
	}

	/**
	 * This method tests the process of retrieving child's E-ticket.
	 * This method checks that we cannot retrieve child's E-ticket with an illegal child ID number.
	 * This method checks that we cannot retrieve child's E-ticket with a child ID number which does not exist in the central computer.
	 * This method checks that we can retrieve child's E-ticket with legal parameters.
	 * 
	 * @throws XMLRidesParserException
	 * @throws GuardianAlreadyExist
	 * @throws GuardianIDDoesntExist
	 * @throws InvalidHeightParam
	 * @throws InvalidAgeParam
	 * @throws ChildAlreadyExist
	 * @throws InvalidRideName
	 * @throws InvalidCapacity
	 * @throws InvalidRideId
	 * @throws ChildIDDoesntExist
	 * @throws RideIDDoesntExist
	 * @throws InvalidGuardianID
	 * @throws InvalidChildID
	 */
	@Test
	public void testRetrieveChildETicket() throws XMLRidesParserException,
			GuardianAlreadyExist, GuardianIDDoesntExist, InvalidHeightParam,
			InvalidAgeParam, ChildAlreadyExist, InvalidRideName,
			InvalidCapacity, InvalidRideId, ChildIDDoesntExist,
			RideIDDoesntExist, InvalidGuardianID, InvalidChildID {

		CentralComputer cc = new CentralComputer(copyXMLFilePath);
		// creating a guardian and a child for the test.
		cc.addGuardian(legalGuardianIDs[0], billingInfo[0]);
		cc.addChildToGuardian(legalGuardianIDs[0], legalChildIDs[0],
				legalMinAges[0], legalMinHeights[0]);
		// creating a ride for the test
		Integer createdRideID = cc.createRide(legalRideNames[0],
				isExtremeRides[0], legalMaxCapacities[0], legalMinAges[0],
				legalMinHeights[0]);

		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);
		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);
		cc.buyingProcess(createdRideID, legalGuardianIDs[0], legalChildIDs[0]);

		// retrieving an E-Ticket for a child with illegal ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.retrieveChildETicket(illegalChildIDs[i]);
				fail("Tried to retrieve an E-Ticket for a child with an illegal childID value of "
						+ illegalChildIDs[i]);
			} catch (InvalidChildID e) {
			}
		}

		// retrieving an E-Ticket for non-existing child ID numbers.
		for (int i = 0; i < TEST_SIZE; i++) {
			try {
				cc.retrieveChildETicket(nonExistingLegalChildIDs[i]);
				fail("Tried to retrieve an E-Ticket for non-existing child ID  value of "
						+ nonExistingLegalChildIDs[i]);
			} catch (ChildIDDoesntExist e) {
			}
		}
		
		int reg = cc.retrieveChildETicket(legalChildIDs[0]).getRegualrRidesTickets();
		int extreme = 0;
		if (cc.retrieveChildETicket(legalChildIDs[0]).getExtremeRidesList().size() != 0){
			extreme = cc.retrieveChildETicket(legalChildIDs[0]).getExtremeRidesList().get(createdRideID);
		}
		assertTrue((reg + extreme) == 3);
		

	}

}
